function TaskManagerImp(){
}
TaskManagerImp.prototype={
	init:function(){
		this._uid = 0;
		this._tasks = [];
		this._isWork = false;
		this._interval = 50;
		return this;
	},
	setInterval:function(value){
		this._interval = value;
		return this;
	},
	getInterval:function(){
		return this._interval;
	},
	_run:function(){
		if (this._isWork == true){
			return;
		}
		this._isWork = true;
		var mc = this;		
		function onRunTask(){
			var task = mc._tasks.shift();
			if (task){
				try{
					if (task.obj!= undefined){
						task.func.call(task.obj,task.param);
					}else{
						task.func(task.param);
					}
				}catch(e){
					console.error(e);
				}
			}
			if (mc._tasks.length == 0){
				mc._isWork = false;
				return;
			}
			window.setInterval(onRunTask,mc._interval);
		}
		window.setInterval(onRunTask,mc._interval);
	},
	getCount:function(){
		return this._tasks.length;
	},
	clear:function(){
		this._tasks = [];
		return this;
	},
	addTask:function(obj,func,param){
		this._tasks.push({uid:this._uid,obj:obj,func:func,param:param});
		if (this._isWork == false){
			this._run();
		}
		return this._uid++;
	},
	removeTask:function(uid){
		var items = this._tasks;
		for(var i=0;i<items.length;i++){
			if (items[i].uid==uid){
				items.slice(i,1);
				return this;
			}
		}
		return this;
	}
};

var TaskManager = new TaskManagerImp().init();
